<!-- BEGIN PAGE HEADER-->
<style>
    .ibox label {
        margin-left: 8px;
        margin-bottom: 8px;
    }
</style>
<?php $this->load->view('partials/breadcrumb.tpl', Array('_NO_IOSS_NEW' => '1')) ?>
<!-- END PAGE HEADER-->
<!-- BEGIN PAGE CONTENT-->
<script type="text/javascript">
    function defConfirm(url) {
        if (!confirm("确定要删除吗？")) {
            return false;
        }
        window.location.href = url;
        return true;
    }

    $(document).ready(function () {
        $("#reset").click(function () {
            $("select").val('');
            $("input[type='text']").val('');
        });
    });
</script>
<div class="row">
    <div class="col-xs-12">
        <!-- Begin: life time stats -->
        <div class="portlet light">
            <?= form_open('', Array('class' => 'form-inline', 'role' => 'form')) ?>
            <?= search_form_input('receive_account', filterValue('receive_account'), '收款账号', 'class="form-control input-medium"'); ?>
            <?= search_form_dropdown('pay_account', array('' => '选择打款账号...') + $allAccount, filterValue('pay_account'), '打款用账号', 'class="form-control input-xs"'); ?>
            <?= search_form_dropdown('finance_id', array('' => '选择财务...') + $allFinance, filterValue('finance_id'), '所属财务处理人', 'class="form-control input-xs"'); ?>
            <div style="clear:both;height:10px;"></div>
            <?= search_form_input('payhistory_number_perpage', filterValue('payhistory_number_perpage'), '每页显示条数', 'class="form-control input-xs"'); ?>
            <div class="input-group input-large date-picker input-daterange" data-date="" data-date-format="yyyy-mm-dd">
                <input type="text" class="form-control" name="finance_his_create_time_begin"
                       value="<?= filterValue('finance_his_create_time_begin') ?>" placeholder="记录开始时间"
                       autoComplete="off">
                <span class="input-group-addon">to </span>
                <input type="text" class="form-control" name="finance_his_create_time_end"
                       value="<?= filterValue('finance_his_create_time_end') ?>" placeholder="记录结束时间"
                       autoComplete="off">
            </div>
            <button type="button" class="btn default" id="reset">重置条件</button>
            <button type="submit" class="btn green about_search">搜索 <i class="fa fa-search"></i></button>
            <button type="button" class="btn purple" onclick="iBox()">导出选项</button>
            <label style="float: right;margin-right: 20px" class="label label-danger">总计<?php echo $total_number ?>条</label>
            <script>
                function iBox() {
                    $('#choose-field').toggle(500, 'swing')
                }
            </script>
            <?= form_close() ?>
            <div style="display:none;" class="portlet-body" id="choose-field">
                <form action="" method="post" id="export_form">
                    <div class="well well-sm" style="margin: 10px 0;">
                        <div class="checkbox" style="margin-bottom: 15px;">
                            <b><i>请选择要导出的字段：</i></b>
                            <label>
                                <input id="all" type="checkbox">
                                全选/全不选
                            </label>
                        </div>
                        <div class="checkbox ibox">
                            <label>
                                <input name="field[]" value="id" type="checkbox">id
                            </label>
                            <label>
                                <input name="field[]" value="pay_request_id" type="checkbox">所属财务申请
                            </label>
                            <label>
                                <input name="field[]" value="finance_id" type="checkbox">处理财务账户
                            </label>
                            <label>
                                <input name="field[]" value="coin_type" type="checkbox">付款币种
                            </label>
                            <label>
                                <input name="field[]" value="pay_coin_type_amount" type="checkbox">打款金额(付款币种)
                            </label>
                            <label>
                                <input name="field[]" value="pay_amount" type="checkbox">打款金额(RMB)
                            </label>

                            <label>
                                <input name="field[]" value="rate" type="checkbox">对人民币汇率
                            </label>
                            <label>
                                <input name="field[]" value="pay_account" type="checkbox">付款账户
                            </label>
                            <label>
                                <input name="field[]" value="receive_account" type="checkbox">收款账户
                            </label>
                            <label>
                                <input name="field[]" value="remark" type="checkbox">备注
                            </label>
                            <label>
                                <input name="field[]" value="create_time" type="checkbox">创建时间
                            </label>
                            <label>
                                <input name="field[]" value="update_time" type="checkbox">修改时间
                            </label>
                            <input type="hidden" name="file_name" value="pay_history">
                            <input type="hidden" name="page_name" value="finance.payhistory.index">
                            <input type="hidden" name="excel_type" value="PayHistoryExport">
                        </div>
                        <div class="text-right">
                            <button id="export-xls" type="button" class="text-right btn blue-madison">导出xls</button>
                        </div>
                        <script>
                            $('#export-xls').click(function () {
                                var data = $('#export_form').serialize();
                                if (data.indexOf('field') == -1) {
                                    toastr.error('请选择要导出的字段！', '失败');
                                    return false;
                                } else {
                                    var x = 1;
                                    $('#process').modal('show');
                                    setInterval(function () {
                                        y = 1;
                                        x += parseFloat(Math.random(0, 1));
                                        var width = x.toFixed(2) + '%';
                                        if (parseInt(x) >= 99) {
                                            x = y / (y + 1) * 100;
                                            y++;
                                        }
                                        $('#show-process').html(width);
                                        $('#show-process').css('width', width)
                                    }, 1000);
                                    $.ajax({
                                        url: '<?=site_url("/common/ExcelExport/excel_export")?>',
                                        data: $('#export_form').serialize(),
                                        method: 'POST',
                                        dataType: 'json',
                                        success: function (output) {
                                            clearInterval();
                                            $('#show-process').html('100%');
                                            $('#show-process').css('width', '100%');
                                            $('#process').modal('hide');
                                            toastr.success(output.msg, '成功');
                                            document.location.href = '/' + output.url;
                                        },
                                        fail: function (data) {
                                            toastr.error(data.msg, '失败')
                                        }
                                    })
                                }
                            });

                            $('#all').click(function () {
                                $("input[type='checkbox']").each(function () {
                                    if ($(this).prop("checked") == true) {
                                        $("input[type='checkbox']").prop('checked', true);
                                        $("input[type='checkbox']").parent('span').addClass('checked');
                                        return;
                                    } else {
                                        $("input[type='checkbox']").prop('checked', false);
                                        $("input[type='checkbox']").parent('span').removeClass('checked');
                                        return;
                                    }
                                });
                            });
                        </script>
                    </div>
                </form>
            </div>
            <div class="portlet-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="table-scrollable">
                            <table class="table table-hover table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th width="5%">ID</th>
                                    <th width="5%">财务申请记录</th>
                                    <th width="10%">财务处理人</th>
                                    <th width="10%">付款账号</th>
                                    <th width="10%">收款方账号</th>
                                    <th width="5%">付款币种</th>
                                    <th width="8%">付款时对人民币汇率</th>
                                    <th width="8%">付款金额</th>
                                    <th width="8%">付款金额</th>
                                    <th width="10%">创建时间</th>
                                    <th width="10%">修改时间</th>
                                    <th width="10%">备注</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php foreach ($list as $v) { ?>
                                    <tr>

                                        <td><?= $v->id ?></td>
                                        <td>
                                            <?php if($v->pay_request_id):?>
                                            <a class="btn btn-primary btn-sm" target="_blank" href="<?= site_url('/finance/apply/detail/' . $v->pay_request_id) ?>"><?= $v->pay_request_id ?></a>
                                            <?php endif;?>
                                        </td>
                                        <td><?= $allFinance[$v->finance_id]; ?></td>
                                        <td><?= $allAccount[$v->pay_account] ?></td>
                                        <td><?= $v->receive_account ?></td>
                                        <td><?= IOSS_StaticConfig::getcoinTypeInfo($v->coin_type) ?></td>
                                        <td><?= $v->rate ?></td>
                                        <td><?= number_format($v->pay_amount/$v->rate,'2','.','').'('.IOSS_StaticConfig::getcoinTypeInfo($v->coin_type).')' ?></td>
                                        <td><?= $v->pay_amount ?>(RMB)</td>
                                        <td><?= date('Y-m-d H:i:s', $v->create_time) ?></td>
                                        <td><?= date('Y-m-d H:i:s', $v->update_time) ?></td>
                                        <td><?= $v->remark ?></td>
                                    </tr>
                                <?php } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12 text-right">
                        <?= $pagination ?>
                    </div>
                </div>
            </div>
        </div>
        <!-- End: life time stats -->
    </div>
</div>

<div class="modal fade bs-example-modal-lg" id="process" data-backdrop="static" style="margin-top: 20%" tabindex="-1"
     role="dialog" aria-labelledby="myLargeModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">

            <div class="progress progress-striped active" style="height: 20px;">
                <div class="progress-bar progress-bar-info" style="width:0;" role="progressbar" aria-valuenow="0"
                     aria-valuemax="100" aria-valuemin="0" id="show-process">0%
                </div>
            </div>
        </div>
    </div>
</div>
<!-- END PAGE CONTENT-->
